// utils.h
#ifndef TOOL_HH
#define TOOL_HH
#pragma once
#include <string>
#include <limits>
#include <iostream>
#include <string>
#ifdef _WIN32
#include <cstdlib>
#define CLEAR_SCREEN "cls"
#else
#define CLEAR_SCREEN "clear"
#endif


inline void clearInputBuffer() {
    std::cin.clear();
    std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
}


inline double getValidAmount() {
    double amount;
    while (!(std::cin >> amount) || amount <= 0 || amount > 1000000.0) {
        std::cout << "Error: Please enter a valid amount (positive and less than 1,000,000): ";
        clearInputBuffer();
    }
    clearInputBuffer();
    return amount;
}


inline int getValidChoice(int maxChoice) {
    int choice;
    while (!(std::cin >> choice) || choice < 1 || choice > maxChoice) {
        std::cout << "Error: Please enter a number between 1 and " << maxChoice << ": ";
        clearInputBuffer();
    }
    clearInputBuffer();
    return choice;
}


inline std::string getValidName() {
    std::string name;
    while (true) {
        std::getline(std::cin, name);
        if (!name.empty() && name.length() <= 50) {
            break;
        }
        std::cout << "Error: Name must be non-empty and less than 50 characters: ";
    }
    return name;
}


inline void clearScreen() {
    std::system(CLEAR_SCREEN);
}
#endif
